Part One: The VRML Source Code (cone.wrl)

Here is the entire VRML 2.0 source code. Type (or paste) this code into a file called "coneturn.wrl".

#VRML V2.0 utf8

DEF CONE_TRANS Transform {
  translation 0 3 0
  rotation 1 0 0 0
  children [
    DEF TOUCH_SENSOR TouchSensor {}
    Shape {
      appearance Appearance {
        material Material {
          emissiveColor 0.5 0.5 0.5
        }
      }
      geometry Cone { height 2 bottomRadius 1 }
    }
  ]
}

Transform {
  children [
    Shape {
      appearance Appearance {
        material Material {
          emissiveColor 0.4 0.0 1.0
        }
      }
      geometry IndexedFaceSet {
        coord Coordinate3 {
          point [
            10 0 10,
            10 0 -10,
            -10 0 -10,
            -10 0 10
          ]
        }
        coordIndex [
          0, 1, 2, 3, -1
        ]
      }
    }
  ]
}

DEF CONE_SCRIPT Script {
  url "conemove.class"
  scriptType "javabc"
  field SFNode the_cone_trans USE CONE_TRANS
  eventIn SFBool clicked
  eventOut SFRotation theRot
}

ROUTE TOUCH_SENSOR.isActive TO CONE_SCRIPT.clicked
ROUTE CONE_SCRIPT.theRot TO CONE_TRANS.set_rotation

Part Two: The Java Source Code (coneturn.java)

Here is the Java source code. Type or paste this into a file called "coneturn.java".

import vrml.*;
import vs.*;

public class conemove extends Script {
  // Create connection to the rotation event
  SFRotation theRot = (SFRotation)getEventOut("theRot");

  float rotVector[] = new float[4];

  public conemove() {
    rotVector[0] = 1;     // axis around which to rotate
    rotVector[1] = 0;     // "
    rotVector[2] = 0;     // "
    rotVector[3] = 0;    // angle to rotate by (in radians)
  }

  public void clicked(ConstSFBool ev, ConstSFTime time) {
    if (ev.getValue() == true) {    // if mouse is clicked DOWN, ignore
      return;
    } 
    else {          // if mouse is clicked UP, perform the rotation
      rotVector[3] += 0.314f; // rotate by another 18 degrees
      if(rotVector[3] >= 6.284f)
         rotVector[3] -= 6.284f; // pin to range 0 - 360
      theRot.setValue(rotVector)